999A - Mishka and Contest - CodeForces Solution


brute force implementation *800

Please click on ads to support us..

Python Code:

a , k = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
pointer = False
for i in range(a):
	if b[i] <= k:
		count += 1
	else:
		pointer = i+1
		break
if pointer != False:
	for i in range(a-1 , pointer-1 , -1):
		if b[i] <= k:
			count += 1
		else:
			break
print(count)

C++ Code:

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n, k , c;
    cin>>n>>k;
    vector<int>a(n);
    for( int i = 0; i < n; i++){
		cin>>c;
		a[i]= c;}
    int ans = 0 , z = -1;
    for( int i = 0 ; i < n; i++){
		if(a[i] > k){
			z = i;
			break;}
		else{
			ans++;}}
    if( z == -1 && a[0] <= k){
		z = n-1;}
    for( int i = n-1; i > z; --i){
		if(a[i] > k){
			break;}
		else{
			ans++;}}
    cout<<ans;
    return 0;}


Comments

Submit
0 Comments
More Questions

466C - Number of Ways
1146A - Love "A"
1618D - Array and Operations
1255A - Changing Volume
1710C - XOR Triangle
415C - Mashmokh and Numbers
8A - Train and Peter
591A - Wizards' Duel
1703G - Good Key Bad Key
1705A - Mark the Photographer
1707A - Doremy's IQ
1706B - Making Towers
1325B - CopyCopyCopyCopyCopy
1649C - Weird Sum
1324B - Yet Another Palindrome Problem
525A - Vitaliy and Pie
879A - Borya's Diagnosis
1672B - I love AAAB
1673A - Subtle Substring Subtraction
1345A - Puzzle Pieces
711A - Bus to Udayland
779B - Weird Rounding
1703D - Double Strings
1704C - Virus
63A - Sinking Ship
1704B - Luke is a Foodie
298B - Sail
239A - Two Bags of Potatoes
1704E - Count Seconds
682A - Alyona and Numbers